package com.gameplatform.exception.handler;

import com.gameplatform.common.enums.ResultCodeEnum;
import com.gameplatform.exception.BusinessException;
import com.gameplatform.common.response.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<BaseResponse<Void>> handleBusinessException(BusinessException e) {
        log.error("Business error: ", e);
        return ResponseEntity.ok(BaseResponse.error(e.getResultCode(), e.getMessage()));
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<BaseResponse<Void>> handleException(Exception e) {
        log.error("System error: ", e);
        return ResponseEntity.ok(BaseResponse.error(ResultCodeEnum.SYSTEM_ERROR));
    }
} 